package org.frend.rpc.impl;

import com.alibaba.dubbo.config.annotation.Service;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Deployment;
import org.frend.rpc.model.DeploymentModel;
import org.frend.rpc.service.DeploymentService;
import org.springframework.beans.factory.annotation.Autowired;

@Service(timeout = 1200000)
public class DeploymentServiceImpl implements DeploymentService {

    @Autowired
    private RepositoryService repositoryService;

    @Override
    public DeploymentModel deploymentProcessDefinition(String name, String resource) {
        Deployment deployment = repositoryService.createDeployment().name(name).addClasspathResource(resource)
                .deploy();

        DeploymentModel model = new DeploymentModel();
        model.setId(deployment.getId());
        model.setCategory(deployment.getCategory());
        model.setDeploymentTime(deployment.getDeploymentTime());
        model.setName(deployment.getName());
        model.setTenantId(deployment.getTenantId());
        return model;
    }
}
